package com.wistech.search.solr.extend.mongo;

import java.util.List;

import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

@Component
public class CompanyLiveDataDao extends BaseMongoDao {
	private static final String USER_ID_KEY = "userId";

	public List<String> findOnlineUserIds() {
		DBObject q = new BasicDBObject();
		q.put("online", Boolean.TRUE);
		List<String> userIds = Lists.newArrayList();
		DBCursor cursor = getDbCollection().find(q);
		while (cursor.hasNext()) {
			Object userId = cursor.next().get(USER_ID_KEY);
			if (userId != null) {
				userIds.add(String.valueOf(userId));
			}
		}
		return userIds;
	}

	@Override
	String getCollectionName() {
		return "company";
	}
}
